//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>

#include "ListBindingSitePrediction.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int main (int argc, char** argv) {
  
  String* filenamePatternsAA;
  String* filenamePatternsCH;
  String* filenamePatternsPH;
  String* filenamePatternsSS;
  String* filenamePatternsMT;
  
  float   presisionPatternsAA;
  float   presisionPatternsCH;
  float   presisionPatternsPH;
  float   presisionPatternsSS;
  float   presisionPatternsMT;
  
  String* filenameCATH;
  String* filenameAnchorResidues;

  String* filenameOut;

  if (argc < 14) {
    
    cout << "Error in the input parameters! Must by like: " << endl;
    cout << "./LocalizeBindingSiteByPatternsLengthWeighted <Filename Patterns AA> <Precision>";
    cout <<                                               "<Filename Patterns CH> <Precision> ";
    cout <<                                               "<Filename Patterns PH> <Precision> ";
    cout <<                                               "<Filename Patterns SS> <Precision> ";
    cout <<                                               "<Filename Patterns MT> <Precision> ";
    cout <<                                               "<Filename CATH Profile> ";
    cout <<                                               "<Filename Anchor Residues> ";
    cout <<                                               "<Filename Out>";
    cout << endl;
    
    return 0;
    
  }
  else {
    
    filenamePatternsAA      = new String(argv[1]); presisionPatternsAA = atof(argv[2]);
    filenamePatternsCH      = new String(argv[3]); presisionPatternsCH = atof(argv[4]);
    filenamePatternsPH      = new String(argv[5]); presisionPatternsPH = atof(argv[6]);
    filenamePatternsSS      = new String(argv[7]); presisionPatternsSS = atof(argv[8]);
    filenamePatternsMT      = new String(argv[9]); presisionPatternsMT = atof(argv[10]);
    filenameCATH            = new String(argv[11]);
    filenameAnchorResidues  = new String(argv[12]);
    filenameOut             = new String(argv[13]);
    
    cout << "---------------------------------------------------------------------------------" << endl;
    cout << "     Filename Patterns AA : " << argv[1] << endl;
    cout << "             Precision AA : " << argv[2] << endl;
    cout << "     Filename Patterns CH : " << argv[3] << endl;
    cout << "             Precision CH : " << argv[4] << endl;
    cout << "     Filename Patterns PH : " << argv[5] << endl;
    cout << "             Precision PH : " << argv[6] << endl;
    cout << "     Filename Patterns SS : " << argv[7] << endl;
    cout << "             Precision SS : " << argv[8] << endl;
    cout << "     Filename Patterns MT : " << argv[9] << endl;
    cout << "             Precision MT : " << argv[10] << endl;
    cout << "    Filename CATH Profile : " << argv[11] << endl;
    cout << " Filename Anchor Residues : " << argv[12] << endl;
    cout << "             Filename Out : " << argv[13] << endl;
    cout << "---------------------------------------------------------------------------------" << endl;
    
  }
  
  ListBindingSitePrediction* listBindingSitePrediction = new ListBindingSitePrediction ();
  
  cout << "Preparing files..." << endl;
  listBindingSitePrediction->FilenameCATH(filenameCATH);
  listBindingSitePrediction->FilenameAnchorResidues(filenameAnchorResidues);
  listBindingSitePrediction->FilenameOut(filenameOut);
  
  cout << "Loading data..." << endl;
  if (!listBindingSitePrediction->LoadData()) 
    cout << "Error loading data..." << endl;
  
  cout << "Getting anchor residues..." << endl;
  if (!listBindingSitePrediction->FillAnchorPositions())
    cout << "Error getting anchor residues..." << endl;
  
  cout << "Localizing the binding sites..." << endl;
  if (!listBindingSitePrediction->PredictBindingSiteLengthWeighted(filenamePatternsAA, presisionPatternsAA, 
                                                                   filenamePatternsCH, presisionPatternsCH,  
                                                                   filenamePatternsPH, presisionPatternsPH,  
                                                                   filenamePatternsSS, presisionPatternsSS,  
                                                                   filenamePatternsMT, presisionPatternsMT,  
                                                                   SCORE_NORMALIZED))
    cout << "Error localizing the binding sites..." << endl;

  cout << "Writing results..." << endl;
  if (!listBindingSitePrediction->OutToCSVFile())
    cout << "Error writing results..." << endl;
  
  cout << "Finished..." << endl << "Good Bye" << endl;
  
  if (listBindingSitePrediction) delete listBindingSitePrediction;
  if (filenamePatternsAA)        delete filenamePatternsAA;
  if (filenamePatternsCH)        delete filenamePatternsCH;
  if (filenamePatternsPH)        delete filenamePatternsPH;
  if (filenamePatternsSS)        delete filenamePatternsSS;
  if (filenamePatternsMT)        delete filenamePatternsMT;
  if (filenameCATH)              delete filenameCATH;
  if (filenameAnchorResidues)    delete filenameAnchorResidues;
  if (filenameOut)               delete filenameOut;

  return EXIT_SUCCESS;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//


